Sealed classes: Some times we want to prevent the class from inheritance. To prevent a class from being inherited, precede its declaration with sealed.

  1. sealed is a keyword
  2. sealed classes are not inheritable
  3. sealed methods are not overridable
  4. when a class is providing full functionality it is recommended to declare the class as sealed.

Syntax:
sealed class classsname
{
Body of the class
}

Program on sealed classes
using System;
sealed class rect
{
int l, b;
public void get(int x, int y)
{
l = x;
b = y;
}
public void put()
{
Console.WriteLine("Rectangle" + (l * b));
}
}
class vision
{
public static void Main(String[] args)
{
rect r = new rect();
r.get(4, 3);
r.put();
}
}

Note: Rect class is not possible to inherit to any other class because it is sealed